package cn.iocoder.yudao.module.robot.service.callrecord;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import cn.iocoder.yudao.module.robot.controller.admin.callrecord.vo.*;
import cn.iocoder.yudao.module.robot.dal.dataobject.callrecord.RobotCallRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.robot.dal.mysql.callrecord.RobotCallRecordMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 机器人通话记录 Service 实现类
 *
 * @author 数创万维
 */
@Service
@Validated
public class RobotCallRecordServiceImpl implements RobotCallRecordService {

    @Resource
    private RobotCallRecordMapper robotCallRecordMapper;

    @Override
    public Long createCallRecord(CallRecordSaveReqVO createReqVO) {
        // 插入
        RobotCallRecordDO callRecord = BeanUtils.toBean(createReqVO, RobotCallRecordDO.class);
        robotCallRecordMapper.insert(callRecord);
        // 返回
        return callRecord.getId();
    }

    @Override
    public void updateCallRecord(CallRecordSaveReqVO updateReqVO) {
        // 校验存在
//        validateCallRecordExists(updateReqVO.getId());
        // 更新
        RobotCallRecordDO updateObj = BeanUtils.toBean(updateReqVO, RobotCallRecordDO.class);
        robotCallRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteCallRecord(Long id) {
        // 校验存在
//        validateCallRecordExists(id);
        // 删除
        robotCallRecordMapper.deleteById(id);
    }

//    private void validateCallRecordExists(Long id) {
//        if (callRecordMapper.selectById(id) == null) {
//            throw exception(CALL_RECORD_NOT_EXISTS);
//        }
//    }

    @Override
    public RobotCallRecordDO getCallRecord(Long id) {
        return robotCallRecordMapper.selectById(id);
    }

    @Override
    public PageResult<RobotCallRecordDO> getCallRecordPage(CallRecordPageReqVO pageReqVO) {
        return robotCallRecordMapper.selectPage(pageReqVO);
    }

}